ARD2  RC2
Airbag Reference Demonstrator using MPC5604P
freemaster_scope.c
Go to the documentation of this file.
00001 /******************************************************************************
00002 *
00003 * Freescale Semiconductor Inc.
00004 * (c) Copyright 2004-2011 Freescale Semiconductor
00005 * ALL RIGHTS RESERVED.
00006 *
00007 ****************************************************************************/
00019 #include "freemaster.h"
00020 #include "freemaster_private.h"
00021 #include "freemaster_protocol.h"
00022 
00023 #if FMSTR_USE_SCOPE && !FMSTR_DISABLE
00024 
00025 /***********************************
00026 *  local variables 
00027 ***********************************/
00028 
00029 static FMSTR_U8  pcm_nScopeVarCount;        /* number of active scope variables */
00030 static FMSTR_ADDR  pcm_pScopeVarAddr[FMSTR_MAX_SCOPE_VARS]; /* addresses of scope variables */
00031 static FMSTR_SIZE8 pcm_pScopeVarSize[FMSTR_MAX_SCOPE_VARS]; /* sizes of scope variables */
00032 
00033 /**************************************************************************/
00039 void FMSTR_InitScope(void)
00040 {   
00041 }
00042 
00043 /**************************************************************************/
00054 FMSTR_BPTR FMSTR_SetUpScope(FMSTR_BPTR pMessageIO)
00055 {
00056     FMSTR_BPTR pResponse = pMessageIO;
00057     FMSTR_U8 i, sz, nVarCnt;
00058 
00059     /* uninitialize scope */
00060     pcm_nScopeVarCount = 0U;
00061 
00062     /* seek the setup data */
00063     pMessageIO = FMSTR_SkipInBuffer(pMessageIO, 2U);
00064     
00065     /* scope variable count  */
00066     pMessageIO = FMSTR_ValueFromBuffer8(&nVarCnt, pMessageIO);
00067 
00068     /* scope variable information must fit into our buffers */
00069     if(!nVarCnt || nVarCnt > (FMSTR_U8)FMSTR_MAX_SCOPE_VARS)
00070     {
00071         return FMSTR_ConstToBuffer8(pResponse, FMSTR_STC_INVBUFF);
00072     }
00073     
00074     /* get all addresses and sizes */
00075     for(i=0U; i<nVarCnt; i++)
00076     {
00077         /* variable size */
00078         pMessageIO = FMSTR_ValueFromBuffer8(&sz, pMessageIO);
00079         pcm_pScopeVarSize[i] = sz;
00080         
00081         /* variable address */
00082         pMessageIO = FMSTR_AddressFromBuffer(&pcm_pScopeVarAddr[i], pMessageIO);
00083 
00084         /* valid numeric variable sizes only */
00085         if(sz == 0U || sz > 8U)
00086         {
00087             return FMSTR_ConstToBuffer8(pResponse, FMSTR_STC_INVSIZE);
00088         }
00089         
00090 #if FMSTR_CFG_BUS_WIDTH > 1U
00091         /* even sizes only */
00092         if(sz & 0x1)
00093         {
00094             return FMSTR_ConstToBuffer8(pResponse, FMSTR_STC_INVSIZE);
00095         }
00096 #endif
00097         
00098 #if FMSTR_USE_TSA && FMSTR_USE_TSA_SAFETY
00099         if(!FMSTR_CheckTsaSpace(pcm_pScopeVarAddr[i], (FMSTR_SIZE8) sz, 0U))
00100         {
00101             return FMSTR_ConstToBuffer8(pResponse, FMSTR_STC_EACCESS);
00102         }
00103 #endif
00104         
00105     }
00106 
00107     /* activate scope */
00108     pcm_nScopeVarCount = nVarCnt;
00109 
00110     /* return just a status */
00111     return FMSTR_ConstToBuffer8(pResponse, FMSTR_STS_OK);
00112 }
00113 
00114 /**************************************************************************/
00125 FMSTR_BPTR FMSTR_ReadScope(FMSTR_BPTR pMessageIO)
00126 {
00127     FMSTR_U8 i;
00128     
00129     if(!pcm_nScopeVarCount)
00130     {
00131         return FMSTR_ConstToBuffer8(pMessageIO, FMSTR_STC_NOTINIT);
00132     }
00133     
00134     /* success */
00135     pMessageIO = FMSTR_ConstToBuffer8(pMessageIO, FMSTR_STS_OK);
00136     
00137     for (i=0U; i<pcm_nScopeVarCount; i++)
00138     {
00139         pMessageIO = FMSTR_CopyToBuffer(pMessageIO, pcm_pScopeVarAddr[i], pcm_pScopeVarSize[i]);
00140     } 
00141         
00142     /* return end position */
00143     return pMessageIO;  
00144 }
00145 
00146 #else  /* FMSTR_USE_SCOPE && !FMSTR_DISABLE */
00147 
00148 /*lint -efile(766, freemaster_protocol.h) include file is not used in this case */
00149 
00150 #endif /* FMSTR_USE_SCOPE && !FMSTR_DISABLE */
00151